/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package zaizai.com.slice;

import com.ajguan.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.text.Font;

/**
 * 主界面
 * Enumerates color blend modes.
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button titleBar = (Button) findComponentById(ResourceTable.Id_title_bar);
        titleBar.setFont(Font.DEFAULT_BOLD);

        Component refresh = (Component) findComponentById(ResourceTable.Id_refresh);
        refresh.setClickedListener(this);
        Component loading = (Component) findComponentById(ResourceTable.Id_loading);
        loading.setClickedListener(this);

        Component refreshLoading = (Component) findComponentById(ResourceTable.Id_refresh_loding);
        refreshLoading.setClickedListener(this);

        Component viewPager = (Component) findComponentById(ResourceTable.Id_m_view_pager);
        viewPager.setClickedListener(this);

        Component adavence = (Component) findComponentById(ResourceTable.Id_m_adavence_model);
        adavence.setClickedListener(this);

    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_refresh:
                startAbility(new OnlyRefreshAbilitySlice());
                break;
            case ResourceTable.Id_loading:
                startAbility(new OnlyLoadingAbilitySlice());
                break;
            case ResourceTable.Id_refresh_loding:
                startAbility(new RefreshLoadingAbilitySlice());
                break;
            case ResourceTable.Id_m_view_pager:
                startAbility(new ViewPagerAbilitySlice());
                break;
            case ResourceTable.Id_m_adavence_model:
                startAbility(new AdavnceModelAbilitySlice());
                break;
        }
    }


    /**
     * 页面跳转
     *
     * @param slice Indicates the target ability slice, which cannot be null.
     */
    private void startAbility(AbilitySlice slice) {
        Intent intent = new Intent();
        /*
         不同ability之间的AbilitySlice跳转
         Operation build = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName((getAbilityInfo().bundleName))
                .withAbilityName(getAbilityInfo().className)
                .build();
        intent.setOperation(build);
        */
        present(slice, intent);
    }
}
